<!-- 人员调岗单 -->
<template>
  <view>
    <u-form
      :model="model"
      :rules="rules"
      ref="form"
      labelPosition="top"
      labelWidth="auto"
      :labelStyle="{
        fontSize: '14px',
        color: '#B2B2B2',
        lineHight: '20px',
      }"
    >
      <view class="basic-style">
        <view class="basic-title basic-border">基本信息</view>
        <u-form-item label="单据编号" prop="billNo" required>
          <u--input v-model="model.billNo" disabled></u--input>
        </u-form-item>
        <u-form-item label="申请时间" prop="createTime" required>
          <u--input
            v-model="model.createTime"
            disabled
            suffixIcon="calendar-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            placeholder="请选择日期"
          ></u--input>
        </u-form-item>
        <u-form-item label="申请人" prop="employeeId" required>
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="model.employeeId"
            placeholder="请选择申请人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="model.employeeId"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="预计到岗时间" prop="arrivalTime" required>
          <h-time-select
            mode="datetime"
            ref="remittanceDate"
            v-model="model.arrivalTime"
            placeholder="请选择预计到岗时间"
            border="surround"
            suffixIcon="calendar-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-time-select>
        </u-form-item>
        <u-form-item label="是否外派" prop="isExpatriate" required>
          <h-select-input-tag
            class="w-100"
            v-model="model.isExpatriate"
            objectField="model.isExpatriate"
            placeholder="请选择是否外派"
            border="surround"
            dictName="yes_or_no"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-select-input-tag>
        </u-form-item>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">调岗信息</view>
        <u-form-item label="调整前部门" prop="beforeDepartId">
          <h-select-depart-input
            disabled
            v-model="model.beforeDepartId"
            :departName="model.beforeDepartText"
            placeholder="请选择部门"
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="model.beforeDepartText"
            @detail="ontenderDeptDetail"
          ></h-select-depart-input>
        </u-form-item>
				<u-form-item label="调整前岗位序列" prop="beforePositionCategory">
				  <h-select-input-tag
				    disabled
				    class="w-100"
				    v-model="model.beforePositionCategory"
				    objectField="model.beforePositionCategory"
				    placeholder="请选择调整前岗位"
				    border="surround"
				    suffixIcon="arrow-down-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				    dictName="position_category"
				  ></h-select-input-tag>
				</u-form-item>
				<u-form-item label="调整前职务级别" prop="beforePositionLevelId">
				  <h-select-input-tag
				    disabled
				    class="w-100"
				    v-model="model.beforePositionLevelId"
				    objectField="model.beforePositionLevelId"
				    placeholder="请选择调整前职务级别"
				    border="surround"
				    suffixIcon="arrow-down-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				    dictName="erp_org_position_level,level_name,id,del_flag='0' and audit_status='2'"
				  ></h-select-input-tag>
				</u-form-item>
        <u-form-item label="调整前岗位" prop="beforePostId">
          <h-select-input-tag
            disabled
            class="w-100"
            v-model="model.beforePostId"
            objectField="model.beforePostId"
            placeholder="请选择调整前岗位"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            dictName="sys_position,name,id,del_flag = 0 and audit_status=2"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="调整前所属团队" prop="beforeTeamId">
          <h-select-team-input
            disabled
            style="width: 100%"
            v-model="model.beforeTeamId"
            objectField="model.beforeTeamId"
            placeholder="请选择调整前所属团队"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            border="surround"
            :tdlx="3"
          />
        </u-form-item>
        <u-form-item label="调整前薪级" prop="beforeSalaryScale">
          <h-select-input-tag
            disabled
            class="w-100"
            v-model="model.beforeSalaryScale"
            objectField="model.beforeSalaryScale"
            placeholder="请选择调整前薪级"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            dictName="erp_pay_grade,salary_grade,id,del_flag = 0 and audit_status=2"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="调整前车贴（元）" prop="beforeVehicleSubsidies">
          <u--input
            type="number"
            v-number-normal
            placeholder="请输入调整前车贴（元）"
            v-model="model.beforeVehicleSubsidies"
            disabled
          ></u--input>
        </u-form-item>
        <u-form-item label="调整后部门" prop="afterDepartId" required>
          <h-select-depart-input
            v-model="model.afterDepartId"
            :departName="model.afterDepartIdText"
            placeholder="请选择调整后部门"
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="model.afterDepartIdText"
            @detail="ontenderDeptDetail"
          ></h-select-depart-input>
        </u-form-item>
				<u-form-item label="调整后岗位序列" prop="afterPositionCategory" required>
				  <h-select-input-tag
				    class="w-100"
				    v-model="model.afterPositionCategory"
				    objectField="model.afterPositionCategory"
				    placeholder="请选择调整后岗位序列"
				    border="surround"
				    suffixIcon="arrow-down-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				    dictName="position_category"
				  ></h-select-input-tag>
				</u-form-item>
				<u-form-item label="调整后职务级别" prop="afterPositionLevelId" required>
				  <h-select-input-tag
				    class="w-100"
				    v-model="model.afterPositionLevelId"
				    objectField="model.afterPositionLevelId"
				    placeholder="请选择调整后职务级别"
				    border="surround"
				    suffixIcon="arrow-down-fill"
				    :suffixIconStyle="{ color: '#B2B2B2' }"
				    :dictName="positionLevelIdDict"
				  ></h-select-input-tag>
				</u-form-item>
        <u-form-item label="调整后岗位" prop="afterPostId" required>
          <h-select-input-tag
            class="w-100"
            v-model="model.afterPostId"
            objectField="model.afterPostId"
            placeholder="请选择调整后岗位"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :dictName="positionIdDict"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="调整后所属团队" prop="afterTeamId" required>
          <h-select-team-input
            style="width: 100%"
            v-model="model.afterTeamId"
            objectField="model.afterTeamId"
            placeholder="请选择调整后所属团队"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            border="surround"
            :tdlx="3"
          />
        </u-form-item>
        <u-form-item label="调整后薪级" prop="afterSalaryScale" required>
          <h-select-input-tag
            class="w-100"
            v-model="model.afterSalaryScale"
            objectField="model.afterSalaryScale"
            placeholder="请选择调整后薪级"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            border="surround"
            dictName="erp_pay_grade,salary_grade,id,del_flag = 0 and audit_status=2"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="调整后车贴（元）" prop="afterVehicleSubsidies" required>
          <h-money-input placeholder="请输入调整后车贴（元）" v-model="model.afterVehicleSubsidies"></h-money-input>
        </u-form-item>
        <u-form-item label="调整原因" prop="adjustReason" required>
          <u--textarea :confirm-type="null" maxlength="500" count v-model="model.adjustReason" placeholder="请输入调整原因"></u--textarea>
        </u-form-item>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">交接信息</view>
        <u-form-item label="工作交接" prop="isWorkHandover" :borderBottom="false" required>
          <h-dict-radio v-model="model.isWorkHandover" dictName="YES_OR_NO" @change="workHandoverChange"></h-dict-radio>
        </u-form-item>
          <u-form-item v-if="model.isWorkHandover == '1'" label="交接人" prop="workHandoverPerson" :borderBottom="false" required>
            <h-select-person-input
              style="width: 100%"
              v-model="model.workHandoverPerson"
              placeholder="请选择工作交接人"
              border="surround"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
              objectField="model.workHandoverPerson"
            ></h-select-person-input>
          </u-form-item>
        <u-form-item label="办公设备交接情况" prop="isOfficeSupplies" :borderBottom="false" required>
          <h-dict-radio v-model="model.isOfficeSupplies" dictName="YES_OR_NO" @change="officeSuppliesChange"></h-dict-radio>
        </u-form-item>
          <u-form-item v-if="model.isOfficeSupplies == '1'" label="接收人" prop="officeSuppliesPerson" :borderBottom="false" required>
            <h-select-person-input
              style="width: 100%"
              v-model="model.officeSuppliesPerson"
              placeholder="请选择办公设备交接人"
              border="surround"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
              objectField="model.officeSuppliesPerson"
            ></h-select-person-input>
          </u-form-item>
        <u-form-item label="有无借款" prop="isLoan" :borderBottom="false" required>
          <h-dict-radio v-model="model.isLoan" dictName="YES_OR_NO" @change="loanChange"></h-dict-radio>
        </u-form-item>
          <u-form-item v-if="model.isLoan == '1'" label="借款金额" prop="loanMoney" :borderBottom="false" required>
            <h-money-input placeholder="请输入借款金额" v-model="model.loanMoney"></h-money-input>
            <!-- <u--input v-number-normal v-model="model.loanMoney" placeholder="请输入借款金额" border="surround"></u--input> -->
          </u-form-item>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">附件信息</view>
        <view class="py-1 space-y-1" style="width: 100%">
          <view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
          <h-upload-file v-model="model.attachment" :isIcon="false"></h-upload-file>
          <file-list v-if="model.attachment" v-model="model.attachment" :isDelete="true"></file-list>
        </view>
      </view>

      <view class="space-x-1 px-1 btn_position">
        <u-button :disabled="isSubmit" type="primary" :plain="true" text="保存草稿" @click="onDraft"></u-button>
        <u-button :disabled="isSubmit" type="primary" text="保存并提交" @click="onSubmit"></u-button>
      </view>
      <view style="height: 100rpx"></view>
    </u-form>

    <u-toast ref="uToast"></u-toast>
    <ProcessNodeConfiguration ref="processConfig" @ok="onOk"></ProcessNodeConfiguration>
  </view>
</template>
  
  <script>
import { mapState } from 'vuex'
import moment from 'moment'
import { gainBillNo, add, info, edit, queryPostRecordByInfo, queryFileById } from '@/api/work/ErpHrEmployeeAdjustPostBillForm'

import fileList from '@/pages/synergy/components/fileList.vue'
//   import Form from './components/ErpPurchaseApplyMaterialForm.vue'
//   import FormInfo from './components/ErpPurchaseApplyMaterialFormInfo.vue'
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
export default {
  name: 'ErpHrEmployeeAdjustPostBillForm',
  components: {
    fileList,
    //   Form,
    //   FormInfo,
    ProcessNodeConfiguration,
  },
  data() {
    return {
      isSubmit: false, // 控制按钮是否可以点击
      backUpProvisionBroad: '',
      showBusinessSegment: false,
      exportTeamId: '',
      flag: false,
      index: null,
      showFormModal: false,
      confirmModal: false,
      loading: false,
      id: '',
      exportWarehouseList: [],
      foldWarehouseList: [],
      dataSource2: [],
      basicForm: {},
      // formData: [],
      // api: {
      //   queryProvisionBroadList,
      // },
			positionIdDict: 'sys_position,name,id,del_flag = 0 and audit_status=2 and is_virtual=0',
			positionLevelIdDict: 'erp_org_position_level,level_name,id,del_flag="0" and audit_status="2"',
      model: {
        // 基本信息 - 公用
        bpmBizTitle: '',
        billNo: '',
        createTime: '',
        employeeId: '',
        arrivalTime: '',
        isExpatriate: '',
        beforeDepartId: '',
        beforePositionCategory: '',
				beforePositionLevelId: '',
        beforePostId: '',
        beforeTeamId: '',
        beforeSalaryScale: '',
        beforeVehicleSubsidies: '',
        afterDepartId: '',
				afterPositionCategory: '',
				afterPositionLevelId: '',
        afterPostId: '',
        afterTeamId: '',
        afterSalaryScale: '',
        afterVehicleSubsidies: '',
        adjustReason: '',
        isWorkHandover: '',
        workHandoverPerson: '',
        isOfficeSupplies: '',
        officeSuppliesPerson: '',
        isLoan: '',
        loanMoney: '',
        // 附件
        attachment: null,
      },
      //   provisionBroadups: null,
      rules: {
        billNo: [{ required: true, message: '请输入单据编号!', trigger: ['blur', 'change'] }],
        employeeId: [{ required: true, message: '请选择申请人!', trigger: ['blur', 'change'] }],
        createTime: [{ required: true, message: '请选择申请时间!', trigger: ['blur', 'change'] }],

        arrivalTime: [{ required: true, message: '请选择预计到岗时间!', trigger: ['blur', 'change'] }],
        isExpatriate: [{ required: true, message: '请选择是否外派!', trigger: ['blur', 'change'] }],
        afterDepartId: [{ required: true, message: '请选择调整后部门!', trigger: ['blur', 'change'] }],
        afterPositionCategory: [{ required: true, message: '请选择调整后岗位序列!', trigger: ['blur', 'change'] }],
        afterPositionLevelId: [{ required: true, message: '请选择调整后职务级别!', trigger: ['blur', 'change'] }],
        afterPostId: [{ required: true, message: '请选择调整后岗位!', trigger: ['blur', 'change'] }],
        afterTeamId: [{ required: true, message: '请选择调整后所属团队!', trigger: ['blur', 'change'] }],
        afterSalaryScale: [{ required: true, message: '请选择调整后薪级!', trigger: ['blur', 'change'] }],
        afterVehicleSubsidies: [
          { type: 'number', required: true, message: '请输入调整后车贴（元）!', trigger: ['blur', 'change'] },
          { pattern: /^[0-9]*[1-9][0-9]*|0$/, message: '请输入正整数!', trigger: ['blur', 'change'] },
        ],
        adjustReason: [{ required: true, message: '请输入调整原因!', trigger: ['blur', 'change'] }],
        isWorkHandover: [{ required: true, message: '请选择工作交接!', trigger: ['blur', 'change'] }],
        workHandoverPerson: [{ required: true, message: '请选择交接人!', trigger: ['blur', 'change'] }],
        isOfficeSupplies: [{ required: true, message: '请选择办公设备交接情况!', trigger: ['blur', 'change'] }],
        officeSuppliesPerson: [{ required: true, message: '请选择接收人!', trigger: ['blur', 'change'] }],
        isLoan: [{ required: true, message: '请选择有无借款!', trigger: ['blur', 'change'] }],
        loanMoney: [
          { type: 'number', required: true, message: '请输入借款金额（元）!', trigger: ['blur', 'change'] },
          { pattern: /^[0-9]*[1-9][0-9]*|0$/, message: '请输入正整数!', trigger: ['blur', 'change'] },
        ],
      },

      //代码生成后需手动设置流程编码
      processId: '1560089400301527041',
      flowCode: 'onl_erp_hr_employee_adjust_post_bill',
      formUrl: 'erp/hr/adjust/modules/ErpHrEmployeeAdjustPostBillForm',
      formUrlMobile: '/pages/synergy/erpHrEmployeeAdjustPostBillForm',
      beanName: 'erpHrEmployeeAdjustPostBillServiceImpl',
    }
  },
  onLoad({ id }) {
    this.id = id || ''
  },
  created() {
    if (this.id) {
      this.initInfo()
      //   this.initDataList()
    } else {
      this.initForm()
      this.initBillNo()
    }
    // this.initBuyerInfo()
  },
  computed: {
    ...mapState(['userInfo'])
	},
  methods: {
    workHandoverChange($event) {
      if ($event === '0') {
        this.$set(this.model, 'workHandoverPerson', null)
      }
    },
    officeSuppliesChange($event) {
      if ($event === '0') {
        this.$set(this.model, 'officeSuppliesPerson', null)
      }
    },
    loanChange($event) {
      if ($event === '0') {
        this.$set(this.model, 'loanMoney', null)
      }
    },
    // 投标部门详情
    ontenderDeptDetail(item) {
      var title = ''
      if (item && item.length) {
        item.map((value, index) => {
          title = value.departName + ',' + title
        })
        title = title.substring(0, title.lastIndexOf(','))
      }
      this.model.afterDepartIdText = title
    },
    // 获取单据编号
    async initBillNo() {
      const res = await gainBillNo()
      this.model.billNo = res.result
      this.model.bpmBizTitle =
        '人员调岗单' + '-' + this.userInfo?.employee?.name + '-' + moment(this.model.createTime).format('YYYY年MM月DD日')
    },
    // 初始化新增需要的数据
    initForm() {
      this.model.employeeId = this.userInfo.empId //当前登录人
      this.model.beforeDepartId = this.userInfo.deptId //当前登录人部门
      // this.model.beforePostId = this.userInfo.postIds //当前登录人岗位
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss')

      queryPostRecordByInfo({
        employeeId: this.userInfo.empId,
        departId: this.userInfo.deptId,
      }).then((res) => {
        if (res.success) {
          this.$set(this.model, 'beforeTeamId', res.result[0].teamId)
          this.$set(this.model, 'beforePositionCategory', res.result[0].positionCategory)
          this.$set(this.model, 'beforePositionLevelId', res.result[0].positionLevelId)
          this.$set(this.model, 'beforePostId', res.result[0].postId)
        } else {
          this.$u.toast(res.message)
        }
      })
      queryFileById({
        id: this.userInfo.empId,
      }).then((res) => {
        if (res.success) {
          let data = res.result
          this.$set(this.model, 'beforeSalaryScale', data.payGradeId)
          this.$set(this.model, 'beforeVehicleSubsidies', data.carSubsidy)
        } else {
          this.$u.toast(res.message)
        }
      })
    },
    async initInfo() {
      const response = await info({ id: this.id })
      const data = response?.result || {}
      this.model = Object.assign({}, data)
      //   if(!!data.provisionBroad&&data.provisionBroad=='1535176942946377729'){
      //   // 选择的是行政类
      //   this.showBusinessSegment = false;
      //   }else{
      //   // 选择的不是行政类
      //   this.showBusinessSegment = true;
      //   }
      //       this.provisionBroadups = this.model.provisionBroad
    },
    validateForm() {
      return this.$refs.form.validate()
    },
    async onSubmit() {
      await this.validateForm()
      this.isSubmit = true
      try {
        this.loading = true
        var url = ''
        if (this.id) {
          url = edit
        } else {
          url = add
        }
        const response = await url({
          ...this.model,
          // detailList: this.formData,
        })
        if (response.success) {
          var that = this
          // this.isSubmit = true
          // 获取流程列表
          if (this.model.id) {
            this.getProcessList(this.model.id)
          } else {
            // 判断添加的时候是否有返回id值
            if (response.result) {
              this.getProcessList(response.result)
            }
          }
          this.$refs.uToast.show({
            message: response.message,
            type: 'default',
            complete() {
              // that.isSubmit = false
            },
          })
        }
      } finally {
        // this.loading = false
      }
    },
    async onDraft() {
      // await this.validateForm()
      this.isSubmit = true
      try {
        this.loading = true
        var url = ''
        if (this.id) {
          url = edit
        } else {
          url = add
        }
        const response = await url({
          ...this.model,
          // detailList: this.formData,
        })
        if (response.success) {
          // this.isSubmit = true
          this.$refs.uToast.show({
            message: response.message,
            type: 'default',
            complete() {
              this.isSubmit = false
              if (getCurrentPages().length > 1) {
                uni.navigateBack()
              } else {
                uni.reLaunch({
                  url: '/pages/home/home',
                })
              }
            },
          })
        }
      } finally {
        this.loading = false
      }
    },
    // 获取流程列表
    getProcessList(id) {
      if (this.isSubmit) {
        this.$refs.processConfig.showPopup = true
        this.$refs.processConfig.formUrl = this.formUrl
        this.$refs.processConfig.formUrlMobile = this.formUrlMobile
        this.$refs.processConfig.flowCode = this.flowCode
        this.$refs.processConfig.edit(id, this.processId, this.beanName)
      }
    },
    // 提交流程成功
    onOk() {
      this.$refs.uToast.show({
        message: '提交成功',
        type: 'success',
        complete() {
          if (getCurrentPages().length > 1) {
            uni.navigateBack()
          } else {
            uni.reLaunch({
              url: '/pages/home/home',
            })
          }
        },
      })
    },
  }
}
</script>
  
  <style scoped lang="scss">
@import url('@/assets/inputStyle.scss');
.trip-form-data {
  ::v-deep {
    .u-form-item__body {
      padding-top: 2px;
      padding-bottom: 2px;
    }
  }
}
.checkbox-item {
  display: flex;
  align-items: center;
}
</style>
  